/*****************************************************************************
* Copyright (c) 2014,H.B.
* All rights reserved.
* 
* FileName : DtvDemux.java
* Description : define DtvDemux
* 
* Version : 0.0.0
* Author : HB   Reviewer : 
* Date : 2014-07-07
* Record : Create
*
* History : 
* (1) Version : 0.0.0
*     Author : HB   Reviewer : 
*     Date : 2014-07-07
*     Record : Create
****************************************************************************/

package hb.dtv;


public class DtvDemux
{
	public static class Capability
	{
		public int DemuxCount;
		public int ChannelCount;
		public int FilterCount;
		public int DescramblerCount;
		
		private Capability(int demux,int channel,int filter,int desc)
		{
			DemuxCount=demux;
			ChannelCount=channel;
			FilterCount=filter;
			DescramblerCount=desc;
		}
	}

	final int mJniPtr;

	DtvDemux(int ptr)
	{
		mJniPtr=ptr;
	}
	
	public void Release()
	{
		nativeRelease(mJniPtr);
	}

	public void LinkTuner(DtvTuner tuner)
	{
		nativeLinkTuner(mJniPtr,tuner.mJniPtr);
	}
	
	public void UnlinkTuner()
	{
		nativeUnlinkTuner(mJniPtr);
	}

	public DtvSignal CreateSignal()
	{
		int ptr=nativeCreateSignal(mJniPtr);
		return new DtvSignal(ptr);
	}

	public DtvBuffer CreateBuffer(int size)
	{
		int ptr=nativeCreateBuffer(mJniPtr,size);
		return new DtvBuffer(ptr);
	}

	public DtvChannel CreateChannel(int type,boolean crc,int bufferSize)
	{
		int ptr=nativeCreateChannel(mJniPtr,type,crc,bufferSize);
		return new DtvChannel(ptr);
	}

	public DtvFilter CreateFilter(byte[] mask,byte[] match,byte[] negate)
	{
		int ptr=nativeCreateFilter(mJniPtr,mask,match,negate);
		return new DtvFilter(ptr);
	}

	public DtvDescrambler CreateDescrambler(int caType,int descType,int entropy)
	{
		int ptr=nativeCreateDescrambler(mJniPtr,caType,descType,entropy);
		return new DtvDescrambler(ptr);
	}

	public int GetFreeChannelCount()
	{
		return nativeGetFreeChannelCount(mJniPtr);
	}
	
	public int GetFreeFilterCount()
	{
		return nativeGetFreeFilterCount(mJniPtr);
	}

	public int GetFreeDescramblerCount()
	{
		return nativeGetFreeDescramblerCount(mJniPtr);
	}

	public int GetIndex()
	{
		return nativeGetIndex(mJniPtr);
	}

	@Override
	public boolean equals(Object o) 
	{
		 if (this == o) return true;
		 if (!(o instanceof DtvDemux)) return false;
		 DtvDemux d=(DtvDemux)o;
		 if(mJniPtr==d.mJniPtr)return true;
		 return GetIndex()==d.GetIndex();
	}

	@Override
	protected void finalize() throws Throwable
	{
		nativeDestroy(mJniPtr);
		super.finalize();
	}

	private native static void nativeLinkTuner(int jniPtr,int tuner);
	
	private native static void nativeUnlinkTuner(int jniPtr);
	
	private native static int nativeCreateSignal(int jniPtr);
	
	private native static int nativeCreateBuffer(int jniPtr,int size);
	
	private native static int nativeCreateChannel(int jniPtr,
		int type,boolean crc,int bufferSize);
	
	private native static int nativeCreateFilter(int jniPtr,
		byte[] mask,byte[] match,byte[] negate);
	
	private native static int nativeCreateDescrambler(int jniPtr,
		int caType,int descType,int entropy);
	
	private native static int nativeGetFreeChannelCount(int jniPtr);
	
	private native static int nativeGetFreeFilterCount(int jniPtr);
	
	private native static int nativeGetFreeDescramblerCount(int jniPtr);

	private native static int nativeGetIndex(int jniPtr);

	private native static void nativeRelease(int jniPtr);

	private native static void nativeDestroy(int jniPtr);
}

